package com.tanhua.management.controller;

import com.tanhua.domain.mongo.Questionnaire;
import com.tanhua.domain.vo.AllQuestionsVo;
import com.tanhua.domain.vo.PageBeanVo;
import com.tanhua.domain.vo.QuestionsVo;
import com.tanhua.management.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Information {
    @Autowired
    private InfoService infoService;

    @GetMapping(value = "/info/users", name = "获取用户列表")
    public ResponseEntity getUserInfo(Integer page, Integer pageSize){
        PageBeanVo pageBeanVo = infoService.getUsers(page, pageSize);
        return ResponseEntity.ok(pageBeanVo);
    }

    @GetMapping(value = "/info/questions", name = "获取题库")
    public ResponseEntity getQuestions(){

        List<Questionnaire> q = infoService.getQuestionnaire();
        return ResponseEntity.ok(q);
    }

    @PostMapping(value = "/questions/submit", name = "创建题库")
    public ResponseEntity submitQues(@RequestBody QuestionsVo questionsVo){
        infoService.createQuestionnaire(questionsVo);
        return ResponseEntity.ok("ok");
    }

    @GetMapping(value = "/questions/get", name = "获取题目")
    public ResponseEntity getInfo(String id){
        AllQuestionsVo vo = infoService.getQuestions(id);
        return ResponseEntity.ok(vo);
    }


}
